﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Tetris
{
    public class FigureGenerator
    {

        public bool[,] figura;
        public bool[,] field;
        public int x = 4;
        public int y = 4;
        public int lastprintedX;
        public int lastprintedY;

        public void FigureI()
        {
            for (int i = 0; i < 4; i++)
                figura[0, i] = true;
        }

        public void FigureJ()
        {
            for (int i = 0; i < 3; i++)
                figura[0, i] = true;
            figura[1, 2] = true;
            
        }
        public void FigureL()
        {
            for (int i = 0; i < 3; i++)
                figura[y, i] = true;
            figura[1, 0] = true;
        }
        public void CallFigure()
        {
            Random rnd = new Random();
            int i = rnd.Next(2, 2);
            if (i == 1)
            {
                FigureI();
                MoveDown();

            }
            if (i == 2)
            {
                FigureJ();
                MoveDown();
            }
            if (i == 3)
            {
                FigureL();
                MoveDown();

            }

        }
        public void InitFigurePosition()
        {
            

        }
        public void InitOnField()
        {
            int koordX = x;
            int koordY = y;
            Console.SetCursorPosition(koordX, koordY);
            Console.CursorVisible = false;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    /*if (figura[i, j] == true)
                    {

                        field[koordY + i, koordX + j] = true;
                        field[koordY + i-1, koordX + j] = false;
                    }*/
                    if (field[i, j] == true)
                    {
                        Console.Write("+");
                    }
                    if (field[i, j] == false)
                    {
                        Console.Write(" ");
                    }
                    if (j == 29)
                        Console.Write("\n");
                }
               
            }
        }

        public void PrintAllFieald()
        {
            for (int i = 0; i < 20; i++)
                for (int j = 0; j < 30; j++)
                {
                    if (field[i, j] == true)
                    {
                        Console.SetCursorPosition(j, i);
                        Console.Write("+");
                    }
                    /*if (field[i,j] == false)
                    {
                        Console.Write(" ");
                    }
                    if (j==29)
                        Console.Write("\n");*/
                }
        }
        

        public void MoveDown()
        {
            do
            {
                Console.Clear();
                InitOnField();
                PrintAllFieald();
                Thread.Sleep(1000);
                y++;
            }
            while (y != 10 && field[y,x] != true);
            x = 1;
            y = 1;
            CallFigure();
            

        }


    }
}
